<?php
/**
 * 
 * 
 * @author mattevigo
 * 
 * @project Sandro del Pistoia
 * @created 19/mar/2009
 */
require_once("DBEntity.php");

class Photo extends DBEntity
{
	const TABLE = 'gallery_photos';
	const PRIMARY_KEY = 'photo_id';
	
	public function __construct(DB $db_wrapper, $id=null)
	{
		parent::__construct($db_wrapper, self::TABLE, self::PRIMARY_KEY, $id);
	}
	
	public function delete()
	{
		parent::cancel();
	}
	
	public function setTitle($title)
	{
		parent::set('photo_title', $title);
	}
	
	public function setCamera($camera)
	{
		parent::set('photo_camera', $camera);
	}
	
	public function setWidth($width)
	{
		parent::set('photo_width', $width);
	}
	
	public function setHeight($height)
	{
		parent::set('photo_height', $height);
	}
	
	public function setDate()
	{
		parent::set('photo_date', null);
	}
	
	public function setDescription($description)
	{
		parent::set('photo_description', $description);
	}
	
	public function setHash($hash)
	{
		parent::set('photo_hash', $hash);
	}
	
	public function setFilename($filename)
	{
		parent::set('photo_filename', $filename);
	}
	
	public function getId()
	{
		return parent::get('photo_id');
	}
	
	public function getTitle()
	{
		return parent::get('photo_title');
	}
	
	public function getCamera()
	{
		return parent::get('photo_camera');
	}
	
	public function getWidth()
	{
		return parent::get('photo_width');
	}
	
	/**
	 * @param string $date_format il formato della data
	 */
	public function getDate($date_format)
	{
		return date($date_format, parent::get('photo_date'));
	}
	
	public function getDescription()
	{
		return nl2br(parent::get('photo_description'));
	}
	
	public function getHash()
	{
		return parent::get('photo_hash');
	}
	
	public function getFilename()
	{
		return parent::get('photo_filename');
	}

	public static function getPhotoFromId($db_wrapper, $id)
	{
		return new Photo($db_wrapper, $id);
	}
}
?>
